<template>
	<view class="publishedParty">
		<view v-for="(item,i) in partyList" :key="item.id">
			<partyItem :item="item" @handleItem='handleItem' @handleBtn="gotoTalk" btnName="组局聊天">
			</partyItem>
		</view>
		<nodata v-if="!partyList || partyList.length==0" nodataText="暂无数据"
			nodataImgUrl="https://file.casugn.com/storecompcard/temp/空页面@2x(14)_1681113729843.png">
		</nodata>
	</view>
</template>

<script>
	import nodata from '@/components/nodata/nodata.vue'
	import partyItem from '@/pagesParty/components/partyItem/partyItem.vue'
	import {
		mapState,
		mapGetters
	} from 'vuex'
	export default {
		components: {
			partyItem,
			nodata
		},
		data() {
			return {
				month: '',
				showPicker: false,
				pickerTime: Number(new Date()),
				queryTime: null,
				partyList: [],
				delItem: null,
				//删除弹框
				delModel: false,
				pageNo: 1,
				pageSize: 10,
				total: 0

			};
		},
		computed: {
			...mapGetters(['userInfo']),
			...mapState(['isCheckingType']),
		},
		created() {
			uni.showLoading({

			})
			// this.nowTime()
			this.queryList()
		},
		onShow() {
			this.showPicker = false
			this.delModel = false
		},
		onPullDownRefresh() {
			this.nowTime()
			this.resetList()
		},
		onReachBottom() {
			if (this.total <= this.pageNo * this.pageSize) {
				uni.showToast({
					title: '没有更多数据',
					icon: 'none'
				})
				return
			} else {
				this.pageNo++
				this.queryList()
			}

		},
		methods: {
			resetList() {
				uni.showLoading({
					title: '加载中'
				})
				this.partyList = []
				this.total = 0
				this.pageNo = 1
				this.queryList()
			},
			//获取当月时间
			nowTime() {
				let now = new Date();
				this.month = now.getMonth() + 1
				const timeFormat = uni.$u.timeFormat
				let str = timeFormat(now, 'yyyy-mm')
				//设定为当月一号
				str = str + '-01'
				console.log(str);
				this.queryTime = str
			},
			//选择时间
			chooseTime() {
				this.showPicker = true
			},
			closePicker() {
				this.showPicker = false
			},
			//时间选择改变
			changeHandler(e) {
				const timeFormat = uni.$u.timeFormat
				let str = timeFormat(e.value, 'yyyy-mm')
				//设定为当月一号
				str = str + '-01'
				console.log(str);
				this.queryTime = str
			},
			confirm(e) {
				const timeFormat = uni.$u.timeFormat
				let str = timeFormat(e.value, 'yyyy-mm')
				let aa = str.split('-')[1].split("")
				if (aa[0] == 0) {
					this.month = aa[1]
				} else {
					this.month = aa[0] + aa[1]
				}
				//设定为当月一号
				str = str + '-01'
				console.log(str);
				this.queryTime = str
				this.showPicker = false
				this.resetList()
			},
			//查询列表信息
			async queryList() {

				let params = {
					category: 1, //1：我发布 
					openId: this.userInfo.openId,
					status: 1, // 1：已发布
					// date: this.queryTime,
					pageNo: this.pageNo,
					pageSize: this.pageSize
				}
				let res = await this.$api.queryReleaseGroupPage(params)
				if (res.success) {
					console.log(res.result.records, '已发布列表信息');
					this.partyList = [...this.partyList, ...res.result.records]
					this.total = res.result.total
				} else {
					uni.showToast({
						title: res.message,
						icon: 'none'
					});
					this.partyList = []
				}
				uni.hideLoading()
				uni.stopPullDownRefresh()
			},
			showModel(
				item
			) {
				this.delItem = item
				this.delModel = true
			},
			async handleDel() {
				let id = this.delItem.id
				let res = await this.$api.deleteGroupInfo(id)
				if (res.success) {
					uni.showToast({
						title: '删除成功',
						icon: 'none'
					});
					this.delModel = false
					this.resetList()
				}
			},
			//显示详情
			handleItem(data) {
				console.log(data, 'data');
				let url = `/pagesParty/party/publishedParty/publishedPartyInfo?id=${data.id}`
				this.$goToPage(url)
			},
			//去聊天
			async gotoTalk(item) {
				console.log(item, '组局信息');
				let payload = {
					roomId: item.roomId,
					openId: this.userInfo.openId

				}
				let res = await this.$api.goOnline(payload)
				if (res.success && res.result) {
					//进入组局聊天
					uni.navigateTo({
						url: `/pagesParty/chatRoom/chatRoom?roomId=${item.roomId}&chatTitle=${item.title}&type=${3}`
					})
				} else {
					return uni.showToast({
						title: res.message,
						icon: 'none'
					})
				}


			},

		}
	}
</script>

<style lang="scss" scoped>
	.publishedParty {
		padding-top: 1rpx;
		min-height: 100vh;
		background-color: #f7f8fa;
	}
</style>